namespace Universal.Application.Contracts.Common;

/// <summary>
/// 通用响应类
/// </summary>
public class ApiResponse<T>
{
    public int Code { get; set; }
    public string Message { get; set; } = string.Empty;
    public T? Data { get; set; }
    // 响应时间
    public DateTime Timestamp { get; set; } = DateTime.UtcNow;

    public ApiResponse(int code, string message, T? data)
    {
        Code = code;
        Message = message;
        Data = data;
        Timestamp = DateTime.UtcNow;
    }

    // 成功响应状态码 200
    public static ApiResponse<T> Success(T data, string message = "请求成功")
    {
        return new ApiResponse<T>(200, message, data);
    }

    // 失败响应状态码 自定义5000-5999
    public static ApiResponse<T> Failure(int code, string message)
    {
        return new ApiResponse<T>(code, message, default);
    }

}